#ifndef NETWORK_SESSION_H
#define NETWORK_SESSION_H


#define BOOST_ASIO_NO_WIN32_LEAN_AND_MEAN
#include <boost/asio.hpp>
#include <boost/thread.hpp>
#ifdef _WIN32
#include <windows.h>
#endif
#include <vector>
/*! Include Updateable Template Header */
#include "../../../Base/Updateable.h"
#include "../../../Base/RecursiveLockingMutex.h"

#ifdef _WIN32
	#include <conio.h>
#else
	#include "../common/conio.h"
#endif

#define NET_SESSION_DEF_PORT  23353

using std::vector;
using mp_base::Updateable;
using mp_base::RecursiveLockingMutex;
using boost::asio::ip::tcp;
using namespace boost::asio;

typedef boost::shared_ptr<tcp::socket> socket_ptr;

namespace mp_net
{
	class NetworkSession : public Updateable, public RecursiveLockingMutex
	{
	public:
		NetworkSession();
		virtual ~NetworkSession();

		virtual void Initialize() = 0;
		virtual void Update() = 0;
		virtual void Uninitialize() = 0;

		virtual void Start() = 0;

		virtual void NetThreadProc() = 0;

	protected:
		void StartOperatingThread();
		void StopOperatingThread();

		vector<tcp::endpoint*>	m_endpoints;
		io_service				m_ioService;	//Common
		socket_ptr				m_socket;		//Common
		int						m_port;
		volatile bool			m_stopRequested;
		boost::thread*			m_operatingThread;
	};
}

#endif